"""
门户网站 - Banner接口
"""
from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select

from app.dependencies import get_db
from app.schemas.common import ResponseModel
from app.models.content import Banner
from app.schemas.content import BannerResponse


router = APIRouter()


@router.get("", response_model=ResponseModel)
async def get_banners(db: AsyncSession = Depends(get_db)):
    """
    获取所有启用的Banner
    """
    result = await db.execute(
        select(Banner)
        .where(Banner.status == 1)
        .order_by(Banner.sort_order.desc(), Banner.created_at.desc())
    )
    banners = result.scalars().all()
    
    return ResponseModel(
        data=[BannerResponse.model_validate(b) for b in banners]
    )

